import java.util.Stack;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-01-23
 * Time: 19:41
 */
public class Solution {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for(int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while(j < popV.length && !stack.empty() && stack.peek().equals(popV[j])) {
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
}
